package com.jinzhi.jinzhidata.service.impl;

import com.jinzhi.jinzhidata.dataobject.Scene;
import com.jinzhi.jinzhidata.repository.SceneRepository;
import com.jinzhi.jinzhidata.service.SceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description
 * @date 2020-01-10 15:51
 **/
@Service
public class SceneServiceImpl implements SceneService {

    @Autowired
    SceneRepository sceneRepository;

    @Override
    public Scene selectBySceneId(String sceneId) {
        return sceneRepository.findById(sceneId).orElse(null);
    }

    @Override
    public Scene insertScene(String sceneId) {
        Scene scene = new Scene();
        scene.setSceneId(sceneId);
        return sceneRepository.save(scene);
    }

    @Override
    public Scene updateTokenBySceneId(String sceneId, String token) {
        Scene scene = sceneRepository.findById(sceneId).orElse(null);
        scene.setToken(token);
        return sceneRepository.save(scene);
    }
}
